# -*- coding: utf-8 -*-
"""
    author: Ye
    date: 2021/01/26 15:37
"""
from flask import g, abort,session, request
from utils.token_jwt import get_res

def user_required(f):
    """Checks whether user is logged in or raises error 401."""
    def decorator(*args, **kwargs):
        # if not g.user:
        print()
        # abort(401)
        token = request.headers.get('token')
        data = get_res(token=token)
        g.username = data['username']
        g.user_id = data['user_id']
        return f(*args, **kwargs)

    return decorator
